package JavaSE.MSB.Thread.C18_FalseSharing;

//程序2比程序1快很多,就是因为加入了一个p1, p2, p3, p4, p5, p6, p7;按行读入
public class T02_CacheLinePadding
{
    private static class Padding
    {
        public volatile long p1, p2, p3, p4, p5, p6, p7;
       // private volatile long p9, p10, p11, p12, p13, p14, p15;
    }
    
    private static class T extends Padding
    {
        public volatile long x = 0L;
    }
    
    public static T[] arr = new T[2];
    
    static
    {
        arr[0] = new T();
        arr[1] = new T();
    }
    
    public static void main(String[] args) throws Exception
    {
        Thread t1 = new Thread(() ->
        {
            for (long i = 0; i < 1000_0000L; i++)
            {
                arr[0].x = i;
            }
        });
        
        Thread t2 = new Thread(() ->
        {
            for (long i = 0; i < 1000_0000L; i++)
            {
                arr[1].x = i;
            }
        });
        
        final long start = System.nanoTime();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println((System.nanoTime() - start) / 100_0000);
    }
}
